﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TimKen.App;

namespace TimKen.Web
{
    public partial class Survey : WebPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SurveyList.SurveyId = SurveyId;
                SurveyList.BindOnlineDropDown(LanguageID);

                if (SurveyList.SurveyDropDown.Items.Count == 0)
                {
                    this.SurveyList.Visible = false;
                    this.SurveyPreview.Visible = false;
                }
                else
                {
                    BindSurvey();
                }
            }

        }

        public int SurveyId
        {
            get
            {
                if (_surveyId == -1)
                {
                    ValidateSurveyId();
                }
                return _surveyId;
            }
            set { _surveyId = value; }
        }

        void ValidateSurveyId()
        {
            if (TypeParse.IsNumeric(Request["SurveyID"]) && int.Parse(Request["SurveyID"]) != -1)
                _surveyId = int.Parse(Request["SurveyID"]);
            else
            {
                if (SurveyList.SurveyDropDown.Items.Count > 0)
                    _surveyId = int.Parse(SurveyList.SurveyDropDown.Items[0].Value);
                else
                    _surveyId = -1;
            }

        }

        public void BindSurvey()
        {

            if (SurveyId != -1)
            {
                this.SurveyPreview.SurveyId = SurveyId;
                this.SurveyPreview.DataBind();
            }
        }

        private int _surveyId = -1;
    }
}